package cn.two.dabeiphotov2.controller;

import cn.two.dabeiphotov2.mapper.OrderListMapper;
import cn.two.dabeiphotov2.pojo.dto.OrderListDto;
import cn.two.dabeiphotov2.pojo.entity.OrderList;
import cn.two.dabeiphotov2.pojo.vo.OrderListUpdateVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/orderList/")
public class OrderListController {
    @Autowired
    OrderListMapper mapper;


    @RequestMapping("select")
    public List<OrderList> select() {
        return mapper.select();
    }

    @RequestMapping("insert")
    public void insert(@RequestBody OrderListDto orderListDto) {
        OrderList orderList = new OrderList();
        BeanUtils.copyProperties(orderListDto, orderList);
        mapper.insert(orderList);
    }

    @RequestMapping("delete")
    public void delete(int id) {
        mapper.deleteById(id);
    }

    @RequestMapping("selectById")
    public OrderListUpdateVo selectById(int id) {
        return mapper.selectById(id);
    }

    @RequestMapping("update")
    public void update(@RequestBody OrderListDto orderListDto) {
        System.out.println("orderListDto = " + orderListDto);
        System.out.println(orderListDto.getId());
        OrderList orderList = new OrderList();
        BeanUtils.copyProperties(orderListDto, orderList);
        int nub = mapper.update(orderListDto);
        System.out.println(nub);
    }
}
